import request from './request'
import { clog, isNull } from '@/utils'

// POST等传参数对象的情况
export function axiosPost(applicationPath, data, prefix = '/api/services/app/') {
    let p = new Promise<any>(function (resolve, reject) {
        request({
            url: prefix + applicationPath,
            method: 'post',
            data: data
        }).then(res => {
            if (isNull(res)) {
                reject('response.data无数据');
            }
            else {
                resolve((res as any).result);
            }
        })
    });
    return p;
}

// 参数在URL中的情况
export function axiosGet(applicationPath, data, prefix = '/api/services/app/') {
    let p = new Promise<any>(function (resolve, reject) {
        request({
            url: prefix + applicationPath,
            method: 'get',
            params: data
        }).then(res => {
            if (isNull(res)) {
                reject('response.data无数据');
            }
            else {
                resolve((res as any).result);
            }
        })
    });
    return p;
}